package com.demonzym.tv.base;

import com.demonzym.tv.R;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

public abstract class BaseFragment extends Fragment{
	
	private ProgressBar mLoading;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View root = inflater.inflate(R.layout.basefragment, null);
		RelativeLayout rl = (RelativeLayout) root.findViewById(R.id.basefragment);
		View view = setContentView(inflater, rl, savedInstanceState);
		view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		rl.addView(view, 0);
		mLoading = (ProgressBar) root.findViewById(R.id.loading);
		return root;
	}
	
	public abstract View setContentView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState);
	
	public void loading(){
		getActivity().runOnUiThread(new Runnable() {
			@Override
			public void run() {
				mLoading.setVisibility(View.VISIBLE);
			}
		});
	}
	public void endLoading(){
		getActivity().runOnUiThread(new Runnable() {
			@Override
			public void run() {
				mLoading.setVisibility(View.GONE);
			}
		});
	}
	
	public void toastSth(String msg){
		((BaseSlidingFragmentActivity)getActivity()).toastSth(msg);
	}
}
